home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
UTILS
/
UTILS.C
< prev
Wrap
Text File
|
1992-12-02
|
8KB
|
366 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 030790 : rewrote CopyStr to not use BlockMove
* SPK 012290 : Initial
*/
#include "SystemPub.h"
/*******************************************************************/
OsType StrToType( char *str )
{
OsType *tp;
int i;
for( i = 0; i < 4; i++ )
if( str[ i ] == '\0' )
for( ; i < 4; i++ )
str[ i ] = ' ';
tp = (OsType *) str;
return( *tp );
}
void TypeToStr( OsType type, char *str )
{
char *t;
int index;
t = (char*) &(type);
for( index = 0; index < 4; index++ )
str[ index ] = t[ index ];
str[ index ] = '\0';
}
/******* CopyStr - copy a pascal string into another ***************/
void CopyStr( char *srcStr, char *dstStr )
{
unsigned int16 srcLen = (unsigned) srcStr[0]+1;
while( srcLen-- )
*dstStr++ = *srcStr++;
}
/********************************************************************/
/* Dialog utilities */
/********************************************************************/
void SetEText( DialogPtr dPtr, int16 item, char *str )
{
int16 theType;
Handle theItem;
Rect theBox;
GetDItem (dPtr, item, &theType, &theItem, &theBox);
if( theItem != NULL )
SetIText (theItem, str);
}
/*******************************************************************/
void GetEText( DialogPtr dPtr, int16 item, char *str )
{
int16 theType;
Handle theItem;
Rect theBox;
GetDItem (dPtr, item, &theType, &theItem, &theBox);
if( theItem != NULL )
GetIText (theItem, str);
}
/*******************************************************************/
void SetCheck( dPtr, ChkItem, Value )
DialogPtr dPtr;
int16 ChkItem;
int16 Value;
{
int16 theType;
Handle theItem;
Rect theBox;
if( Value )
Value = 1;
GetDItem( dPtr, ChkItem, &theType, &theItem, &theBox );
SetCtlValue( theItem, Value );
}
/*******************************************************************/
void GetCheck( dPtr, ChkItem, Value )
DialogPtr dPtr;
int16 ChkItem;
int16 *Value;
{
int16 theType;
Handle theItem;
Rect theBox;
GetDItem (dPtr, ChkItem, &theType, &theItem, &theBox);
*Value = GetCtlValue( theItem );
}
/*******************************************************************/
Boolean GoodNum( numStr )
char *numStr;
{
register int16 i, last = numStr[0];
register unsigned char c;
for (i = 1; i <= last; i++)
{
c = numStr[i];
if((c < '0') || (c > '9'))
return FALSE;
}
return TRUE;
}
Boolean GoodHex( numStr )
char *numStr;
{
register int16 i, last = numStr[0];
register unsigned char c;
for (i = 1; i <= last; i++)
{
c = numStr[i];
if( ((c < '0') || (c > '9')) &&
((c < 'A') || (c > 'F')) &&
((c < 'a') || (c > 'f')) )
return FALSE;
}
return TRUE;
}
/*******************************************************************/
Boolean IsTextLegalInt16( min, max, dPtr, dItem, value )
int16 min, max;
DialogPtr dPtr;
int16 dItem;
int16 *value;
{
char tempNum[ 256 ];
int16 temp;
int32 tempVal;
GetEText( dPtr, dItem, tempNum );
if( GoodNum( tempNum ) )
{
StringToNum( &tempNum, &tempVal );
temp = (int16) tempVal;
if( temp >= min && temp <= max )
{
*value = temp;
return( TRUE );
}
}
SelIText( dPtr, dItem, 0, 32767 );
return( FALSE );
}
/*******************************************************************/
Boolean IsTextLegalInt32( min, max, dPtr, dItem, value )
int32 min, max;
DialogPtr dPtr;
int16 dItem;
int32 *value;
{
char tempNum[256];
int32 temp;
int32 tempVal;
GetEText( dPtr, dItem, tempNum );
if( GoodNum( tempNum ) )
{
StringToNum( &tempNum, &tempVal );
temp = tempVal;
if( temp >= min && temp <= max )
{
*value = temp;
return( TRUE );
}
}
SelIText( dPtr, dItem, 0, 32767 );
return( FALSE );
}
/*******************************************************************/
void pushradiobutton( thedialog, itemhit, first, last )
DialogPtr thedialog;
int itemhit,first,last;
{
int16 itemtype,i;
Handle itemhandle;
Rect itemrect;
if( itemhit < first || itemhit > last || first < 0 )
return;
for( i = first; i <= last; i++ )
{
GetDItem( thedialog, i, &itemtype, &itemhandle, &itemrect );
if( i == itemhit )
SetCtlValue( itemhandle, 1 );
else
SetCtlValue( itemhandle, 0 );
}
}
/*******************************************************************/
void OutlineButton( DialogBox, CornerRad )
DialogPtr DialogBox;
int16 CornerRad;
{
Handle itemhandle;
Rect itembox;
GrafPtr TempPort;
int16 itemtype;
GetPort( &TempPort );
SetPort( DialogBox );
GetDItem( DialogBox, 1, &itemtype, &itemhandle, &itembox );
PenSize( 3,3 );
InsetRect( &itembox, -4, -4 );
FrameRoundRect( &itembox, CornerRad, CornerRad );
PenNormal();
SetPort( TempPort );
}
/*******************************************************************/
extern GrafPtr screenPort;
CenterDialog( DPtr )
GrafPtr DPtr; /* Note : a grafport in a window rec in a dialog rec */
{
Rect D, N, S;
int16 sx, sy, dx, dy;
D = DPtr->portRect;
S = screenPort->portRect;
dx = D.right - D.left;
dy = D.bottom - D.top;
sx = S.right - S.left;
sy = S.bottom - S.top;
N.left = ( sx - dx ) / 2;
N.top = ( sy - dy ) / 3;
if( N.top < 20 )
N.top = 20;
MoveWindow( DPtr, N.left, N.top, false );
ShowWindow( DPtr );
}
/*******************************************************************/
Boolean DialogAsk( char *ask, char *answer )
{
DialogPtr dPtr;
int16 itemHit;
char buf[ 256 ];
dPtr = GetNewDialog( 1011, NULL, -1L );
if( dPtr == NULL )
return;
strcpy( buf, ask );
CtoPstr( buf );
ParamText( buf, NULL, NULL, NULL );
SetArrow();
CenterDialog( dPtr );
OutlineButton( dPtr, 15 );
while( 1 )
{
ModalDialog( NULL, &itemHit );
if( itemHit == OK || itemHit == Cancel )
break;
}
if( itemHit == OK )
{
GetEText( dPtr, 4, answer );
PtoCstr( answer );
DisposDialog( dPtr );
return( TRUE );
}
else
{
strcpy( answer, "" );
DisposDialog( dPtr );
return( FALSE );
}
}